"""
This module defines wine selector objects.
The selectors are widget agnostic, they implement the wine selection only
"""
class Selector(object):
    def __call__(self,o):
        return self.test(o)

    def defaultChoice(self):
        pass

class ColorSelector(object):
    wcolor = 0
    def test(self, b):
        return self.wcolor == b.color

class NumInCellarSelector(object):
        
    def test(self, b):
        pass
    def inCellarSelector(self, b):
        return b.numInStock > 0
    def outCellarSelector(self,b):
        #print ' outCellarSelector ',b.numInStock
        return b.numInStock == 0
    def inCellarOrNomoreSelector(self,b):
        #print ' outCellarSelector ',b.numInStock
        return b.numInStock > -1


    def switch(self, tag):
        if tag == 'incellar':
            NumInCellarSelector.test = NumInCellarSelector.inCellarSelector
        elif tag == 'nomore':
            NumInCellarSelector.test = NumInCellarSelector.outCellarSelector
        elif tag == 'incellarornomore':
            NumInCellarSelector.test = NumInCellarSelector.inCellarOrNomoreSelector
            
class TextSelector(object):
    def test(self,b):
        t = self.text
        return t in b.compactStringBuilder()
